{% extends "layouts/layout01.html" %}

{% load markup i18n mptt_tags model_list thumbnail %}

{% block content %}

    <h2>{% trans "Текстовые поля" %}</h2>
    <div id="container"></div>
    {% with object.text_fields.all as object_list %}
    <table class="table table-bordered table-striped table-highlight">
        <thead>
        <tr>
            <th width="20%">{% trans "Ключ" %}</th>
            <th width="57%">{% trans "Значение" %}</th>
            <th width="23%">{% trans "Действия" %}</th>
        </tr>
        </thead>
        <tbody>
            
        {% for object in object_list %}
            <tr>
                <td>{{ object.key }}</td>
                <td>{{ object.value|safe }}</td>
                <td>
                    
                    <a href="{% url edit_record pk=object.id %}" class="btn btn-secondary">{% trans "Редактировать" %}</a>
                    
                    <a href="{% url delete_record pk=object.id  %}" class="btn btn-danger">
                        <i class="icon-trash"></i>{% trans "Удалить" %}
                    </a>
                    
                </td>
            </tr>
        {% empty %}
        
            <tr>
                <td colspan="3">
                    {% trans "Не создано ни одного поля" %}
                </td>
            </tr>
        {% endfor %}
        </tbody>
        <tfoot>
            <tr>
                <td>
                <!--
                <section id="modals">
                <a class="btn" data-toggle="modal" href="#myModal">{% trans "Создать" %}</a>
                </section>
                -->

                
                <a href="{% url create_record %}" class="btn btn-primary">
                    <i class="icon-star"></i>{% trans "Создать" %}
                </a>
                
                <!--<a href="{% url create_record %}" class="btn" id="aaa">{% trans "Вытащить форму посредством js" %}</a>-->
                </td>
            </tr>
        </tfoot>
    </table>
    {% endwith %}
    
    <h2>{% trans "Графичиские поля" %}</h2>
    <div id="container"></div>

   {% with object.image_fields.all as object_list %}
    <table class="table table-bordered table-striped table-highlight">
        <thead>
        <tr>
            <th>{% trans "Ключ" %}</th>
            <th>{% trans "Значение" %}</th>
            <th width="23%">{% trans "Действия" %}</th>
        </tr>
        </thead>
        <tbody>
            
        {% for object in object_list %}
            <tr>
                <td>{{ object.key }}</td>
                <td>
                    {{ object.value }}<br />
                    {% model_list data IDataImageField object_list %}
                        {% thumbnail object.value "128x128" crop="center" as im %}
                        <img src="{{ im.url }}" />
                        {% endthumbnail %}
                </td>
                <td>
                    
                    <a href="{% url edit_image_record pk=object.id %}" class="btn btn-secondary">{% trans "Редактировать" %}</a>
                    
                    <a href="{% url delete_image_record pk=object.id  %}" class="btn btn-danger">
                        <i class="icon-trash"></i>{% trans "Удалить" %}
                    </a>
                    
                </td>
            </tr>
        {% empty %}
        
            <tr>
                <td>
                    {% trans "Не создано ни одного поля" %}
                </td>
            </tr>
        {% endfor %}
        </tbody>
        <tfoot>
            <tr>
                <td>
                <a href="{% url create_image_record %}" class="btn btn-primary">
                    <i class="icon-star"></i>{% trans "Создать" %}
                </a>
                </td>
            </tr>
        </tfoot>
    </table>
    {% endwith %}
<br /><br /><br />

<div class="btn-group">
    <button class="btn">Добавить</button>
    <button class="btn dropdown-toggle" data-toggle="dropdown">
        <span class="caret"></span>
    </button>
    <ul class="dropdown-menu">
        <li><a href="#">Текстовое поле</a></li>
        <li><a href="#">Графичекое поле</a></li>
        <li><a href="#">Поле с формой обратной связи</a></li>
        <li><a href="#">Поле с сылками</a></li>
        <li class="divider"></li>
        <li><a href="#">Поле с датой и временем</a></li>
        <li><a href="#">Поле только с датой</a></li>
        <li><a href="#">Поле только со временем</a></li>
    </ul>
</div>

<!--    
    {% comment %}  
    <form id="text_form" method="post" target="">{% csrf_token %}
    <input type="hidden" name="form-type" value="text-form" />
    {% with text_formset as formset %}
        {{ formset.management_form }}
        <table id="id_forms_table" class="table table-bordered table-striped table-highlight">
            <thead>
            <tr>
                <th>{% trans "Ключ" %}</th>
                <th>{% trans "Значение" %}</th>
                <th>{% trans "Actions" %}</th>

            </tr>
            </thead>
            <tbody>
            {% for form in formset %}
                <tr id="{{ form.prefix }}-row">
                    <td {% if form.key.errors %}style="background-color: red;"{% endif %}>{% for fld in form.hidden_fields %}{{ fld }}{% endfor %}{{ form.key }}</td>
                    <td {% if form.value.errors %}style="background-color: red;"{% endif %}>{{ form.value }}</td>
                    <td>{% if form.key.value %}
                        <a href="#" class="btn"><i class="icon-trash"></i></a>
                        {% endif %}
                    </td>
                </tr>
            {% empty %}
                <tr>
                    <td colspan="3">
                        {% trans "Не создано не одного поля" %}
                    </td>
                </tr>
            {% endfor %}
            </tbody>
            <tfoot>
            <tr>
                <td colspan="3">
                    <button type="submit" class="btn btn-primary"><i class="icon-star"></i>Сохранить</button>
                    <a class="btn" href="javascript:void(0)" id="add_row">{% trans "Добавить в Сет" %}</a>
                </td>
            </tr>
            </tfoot>
        </table>
    {% endwith %}
    </form>
{% endcomment %}
-->  
    
<!--
{% comment %}
    <h2>{% trans "Графичиские поля" %}</h2>
<div id="container"></div>
    <form id="image_form" method="post" target="" enctype="multipart/form-data">
        {% csrf_token %}
        <input type="hidden" name="form-type" value="image-form" />
        {% with image_formset as formset %}
            {% if formset.errors %}
                <b>{% for error in formset.errors  %}{{ error }}; {% endfor %} </b>
            {% endif %}
            {{ formset.management_form }}
            <table id="id_forms_table" class="table table-bordered table-striped table-highlight">
                <thead>
                <tr>
                    <th>{% trans "Ключ" %}</th>
                    <th>{% trans "Значение" %}</th>
                    <th></th>
                </tr>
                </thead>
                <tbody>
                {% for form in formset %}
                    <b>{% for error in form.errors  %}{{ error }}; {% endfor %} </b>
                    <tr id="{{ form.prefix }}-row" >
                        <td>{% for fld in form.hidden_fields %}{{ fld }}{% endfor %}{{ form.key }}   {% for error in form.key.errors  %}{{ error }}; {% endfor %}</td>
                        <td>{{ form.value }} {% for error in form.value.errors  %}{{ error }}; {% endfor %} </td>
                        <td>{% if form.key.value %}
                            <a href="#" class="btn"><i class="icon-trash"></i></a>
                        {% endif %}
                        </td>
                    </tr>
                {% empty %}
                    <tr>
                        <td colspan="3">
                            {% trans "Не создано не одного поля" %}
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
                <tfoot>
                <tr>
                    <td colspan="3">
                        <button type="submit" class="btn btn-primary">
                            <i class="icon-star"></i>Сохранить</button>
                    </td>
                </tr>
                </tfoot>
            </table>
        {% endwith %}
    </form>
    <br><br>
{% endcomment %}
-->
{% endblock %}

{% block script %}
<script src="{{ STATIC_URL}}js/libs/jquery-1.7.2.min.js"></script>
<script src="{{ STATIC_URL}}js/libs/jquery-ui-1.8.21.custom.min.js"></script>
<script src="{{ STATIC_URL}}js/libs/jquery.ui.touch-punch.min.js"></script>

<script src="{{ STATIC_URL}}js/libs/bootstrap.min.js"></script>

<script src="{{ STATIC_URL}}js/libs/Theme.js"></script>

<script>
$(function () {
    $("#aaa").click(function(){
        $("#container").load( $(this).attr("href")+" #form" );
        return false;
    });
});
</script>   

{% endblock %}

<!-- EOF -->
